import threading

import douyu_main
import panda_main
import zhanqi_main


class LivesThread(threading.Thread):
    def __init__(self, f):
        threading.Thread.__init__(self)
        self.f = f
        self.records = 0

    def run(self):
        self.records = self.f()

    def ret_valuse(self):
        return self.records


class Theads(object):
    def __init__(self):
        self.threads = LivesThread

    def theads(self):
        zq_spider = zhanqi_main.SpiderMain()
        xm_spider = panda_main.SpiderMain()
        dy_spider = douyu_main.SpiderMain()

        thread1 = self.threads(zq_spider.craw)
        thread2 = self.threads(xm_spider.craw)
        thread3 = self.threads(dy_spider.craw)

        thread1.start()
        thread2.start()
        thread3.start()

        thread1.join()
        thread2.join()
        thread3.join()

        xm_records = thread2.ret_valuse()
        zq_records = thread1.ret_valuse()
        dy_records = thread3.ret_valuse()

        return xm_records, zq_records, dy_records

# def f(x, y):
#     for i in range(x, y):
#         print(i)
#         time.sleep(2)
#
#
# thread1 = myThread(f, 1, 10)
# thread2 = myThread(f, 10, 20)
# thread3 = myThread(f, 20, 30)
# thread4 = myThread(f, 30, 40)
#
# thread1.start()
# thread2.start()
# thread3.start()
# thread4.start()
#
# thread1.join()
# thread2.join()
# thread3.join()
# thread4.join()
